<script setup>
import { useRouter } from "vue-router";
import { adminLogout } from "@/apis/admin/user";
import { ref } from "vue";

import {
  List,
  Document,
  Menu as IconMenu,
  Grid,
  Histogram,
  UserFilled,
  Cpu,
  Checked
} from "@element-plus/icons-vue";

// 获取路由对象：单例模式
const route = useRouter();

/**
 * 退出登录
 */
const quit = () => {
  route.push("/");
  // 清空缓存
  sessionStorage.clear;
};

const isCollapse = ref(true);
</script>
<template>
  <el-container>
    <el-header class="el-header">
      <el-menu mode="horizontal" :ellipsis="false">
        <span class="title"> 商城后台管理系统 </span>
        <div style="flex-grow: 1" />
        <el-button class="logout" @click="quit">退出登录</el-button>
      </el-menu>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'" class="el-aside">
        <el-switch
          v-model="isCollapse"
          class="switchCollapase"
          inline-prompt
          style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
          active-text="展开"
          inactive-text="收缩"
        />

        <el-scrollbar class="el-aside-scrollbar">
          <el-menu
            default-active="2"
            class="el-left-menu"
            :router="true"
            :collapse="isCollapse"
          >
            <!-- <el-sub-menu index="/admin/overview">
              <template #title>
                <el-icon><Histogram /></el-icon>
                <span>总览</span>
              </template>
            </el-sub-menu> -->
            <el-menu-item index="/admin/overview">
              <el-icon><Histogram /></el-icon>
              <template #title>总览</template>
            </el-menu-item>
            <el-menu-item index="/admin/manage">
              <el-icon><UserFilled /></el-icon>
              <template #title>用户管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/category">
              <el-icon><Checked /></el-icon>
              <template #title>分类管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/order">
              <el-icon><List /></el-icon>
              <template #title>订单管理</template>
            </el-menu-item>
            <el-menu-item index="/admin/thing">
              <el-icon><icon-menu /></el-icon>
              <template #title>商品管理</template>
            </el-menu-item>
            <!-- <el-menu-item index="/admin/userbehavior">
              <el-icon><Grid /></el-icon>
              <template #title>用户行为管理</template>
            </el-menu-item> -->
            <el-menu-item index="/admin/op-log">
              <!-- <el-icon><Cpu /></el-icon> --> 
              <el-icon><Grid /></el-icon>
              <template #title>用户操作日志</template>
            </el-menu-item>
          </el-menu>
        </el-scrollbar>
      </el-aside>

      <el-main>
        <el-scrollbar class="main-scrollbar">
          <router-view />
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped>
.el-header {
  padding: 0;
}
.el-aside-scrollbar {
  height: calc(100vh - 60px);
  border-right: 0.8px solid rgb(220, 223, 230);
}
.el-left-menu {
  border-right: none;
}
.main-scrollbar {
  height: calc(100vh - 100px);
}
.logout {
  margin-top: 15px;
  margin-right: 10px;
}
.title {
  font-size: 20px;
  font-weight: bold;
  /* text-align: center; */
  margin: 15px;
}
.switchCollapase {
  padding: 5px;
  margin-left: 5px;
}
</style>
